<%= form_for @blog, url: blogs_path, method: :post do |f| %>
  <div class="form-group">
    <ul class="list-unstyled">
      <% @blog.errors.messages.values.flatten.each do |error| %>
        <li><%= error %></li>
      <% end -%>
    </ul>
  </div>

  <div class="form-group">
    <%= f.label :title, "标题" %><br/>
    <%= f.text_field :title, class: "form-control", placeholder: "标题", required: true %>
  </div>
  <div class="form-group">

    <%= f.label :content, "内容" %><br/>
    <div id="test-editormd">

    </div>
    <%= f.text_area :content, class: "form-control", placeholder: "内容", required: true, hidden: true %>
    <div id="editor"></div>
  </div>
  <div class="text-center">
    <%= f.submit "发布", class: 'btn btn-primary' %>
  </div>
<% end -%>

<div id="div1">
</div>
<link rel="stylesheet" href="/css/editormd.css"/>
<script src="/editormd.js"></script>
<script type="text/javascript">
    var testEditor;

    $(function () {
        testEditor = editormd("test-editormd", {
            width: "100%",
            height: 640,
            syncScrolling: "single",
            path: "/lib/",
            htmlDecode: "style,script,iframe",
            placeholder: '开始编写博客吧',
            tex: true,
            emoji: true,
            taskList: true,
            flowChart: true,
            sequenceDiagram: true,
            saveHTMLToTextarea: true,
            toolbarIcons: function () {
                return [
                    "undo", "redo", "|",
                    "bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|",
                    "h1", "h2", "h3", "h4", "h5", "h6", "|",
                    "list-ul", "list-ol", "hr", "|",
                    "link", "reference-link", "image", "code", "preformatted-text", "code-block", "table", "datetime", "html-entities", "pagebreak", "|",
                    "goto-line", "watch", "preview", "fullscreen", "clear", "search", "|",

                ]
            },
            onchange: function () {
                console.log("onchange =>", this.getHTML());
                $('#blog_content').val(this.getHTML())
            }
        });

    });
</script>